<?php
session_start();
//include ('transform.php');
include ('../parametros/bd.php');
$conect = new conector_pg();
$conect-> conectar();
$id=$_GET['id'];

if ($id!= null){
$sql='SELECT *
		from categorias		
		where idcategoria='.$id;
$result = $conect->consultar($sql);
		if (!$result)
		 {
			echo ('Error en la consulta');
			return;
		 }
$valor = pg_fetch_array($result, null, PGSQL_ASSOC);
}


if($_SERVER["REQUEST_METHOD"] == "POST"){
	if (isset($_POST["guardar"])){
		
		$upd="update categorias
				set  descripcion='".$_POST['descripcion']."'
				where idcategoria='".$_POST['idcategoria']."'";
		 
		$result = $conect->consultar($upd);
			if (!$result)
		 	{
				echo 'error en la consulta'	;
				exit;
		 	}else{
		 		header("Location: vercategorias.php");
		 	}		
	}
}

?>
<?php if (isset($_SESSION['logged_in'])) 
	   { 
	   	if ($_SESSION['admin'] == 1)
	   	{ 
?>
<html>
<head>
<link rel="stylesheet" href="../css/style.css" type="text/css" media="screen" />
<link href="../css/imageMenu.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="XoR-main">
			<div class="XoR-sheet">
				<div class="XoR-sheet-tl"></div>
				<div class="XoR-sheet-tr"></div>
				<div class="XoR-sheet-bl"></div>
				<div class="XoR-sheet-br"></div>
				<div class="XoR-sheet-tc"></div>
				<div class="XoR-sheet-bc"></div>
				<div class="XoR-sheet-cl"></div>
				<div class="XoR-sheet-cr"></div>
				<div class="XoR-sheet-cc"></div>
				<div class="XoR-sheet-body">
					<div class="XoR-header">
						<div class="XoR-header-center">
							<div class="XoR-header-png"></div>
							<div class="XoR-header-jpeg"></div>
						</div>
						<div class="XoR-logo">
							<h1 id="name-text" class="XoR-logo-name"><a href="./index.html">Libreria TAI</a></h1>
							<h2 id="slogan-text" class="XoR-logo-text">Primera Libreria Online del Paraguay</h2>
						</div>
					</div>
<h1 id="tituloNaranja2">Edicion de Categorias</h1>
<form action="edicioncategoria.php" method="POST">
<table> 
  <tr>
    <th id="labelLogin">Descripcion</th>
    <td><input type="text" name="descripcion" id="searchForm" value="<?echo $valor['descripcion'];?>"> </td>
  </tr>
  <tr>
  	<td><input style="visibility:hidden" name="idcategoria" type="text" value="<?echo ($id);?>"></td>
  </tr>
</table>

<input type="submit" value="Guardar" id="submitLogin" name="guardar">
</form>

<br>
<a id="labelLogin" href="indexadmin.php"> Regresar al listado </a>
	   	<?php 
	   	}
?>
<a href="../login/logout.php?signature=<?php echo $_SESSION['signature']; ?>
">Logout</a><br /><?php } 
?>
<div class="cleared"></div>
					<div class="XoR-footer">
						<div class="XoR-footer-body">
							<div class="XoR-footer-text">
								<p>Copyright 2011, XoR Company. All Rights Reserved.</p>
							</div>
							<div class="cleared"></div>
						</div>
					</div>
					<div class="cleared"></div>
				</div>
			</div>
			<div class="cleared"></div>
			<p class="XoR-page-footer">Powered by <a href="http://xor.net/">XoR.org</a> </p>
		</div>
</body>  
</html>